﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NNCore
{
    public class DummyLoader : NetLoader
    {
        public NN loadNN()
        {
            NN nn = new NN();
            nn.Layers = createLayer();

            return nn;
        }

        private Layer[] createLayer()
        {
            Layer[] newLayers = new Layer[3];
            newLayers[0] = new Layer();
            newLayers[0].WeightMatrix = null;
            newLayers[1]= new Layer();
            newLayers[1].WeightMatrix = new Matrix(64, 42);
            newLayers[2] = new Layer();
            newLayers[2].WeightMatrix = new Matrix(42, 1);

            SetupLayer(newLayers[0], null, new Identity());
            SetupLayer(newLayers[1], new Tanh(), new Identity());
            SetupLayer(newLayers[2], new Tanh(), new Identity());
            return newLayers;
        }

        public void SetupLayer(Layer layer, AFunction activationFunction, AFunction outputFunction)
        {
            if (layer.WeightMatrix != null)
            {
                for (int i = 0; i < layer.WeightMatrix.Height; i++)
                {
                    for (int j = 0; j < layer.WeightMatrix.Width; j++)
                    {
                        layer.WeightMatrix[i, j] = 0.5;
                    }
                }

                layer.ActivationFunction = activationFunction;
                double[] threshold = new double[layer.WeightMatrix.Width];
                for (int i = 0; i < threshold.Length; i++)
                    threshold[i] = 1.0;

                layer.Threshold = threshold;
            }
            else
            {
                double[] threshold = new double[64];
                for (int i = 0; i < threshold.Length; i++)
                    threshold[i] = 1.0;

                layer.Threshold = threshold;
            }

            layer.OutputFunction = outputFunction;
        }

        public void saveNN(NN saveMe)
        {
            throw new NotImplementedException();
        }
    }
}
